package com.example.smart_city_0829.activity.logistics_inquiries;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.logistics_inquiries.LogisticsCompanyDetail;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.Objects;

import retrofit2.Call;
import retrofit2.Response;

public class LogisticsCompanyDetailActivity extends BaseActivity {

    private Banner banner;
    private TextView introduce;
    private TextView shippingMethod;
    private TextView priceList;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_logistics_comapny_detail;
    }

    @Override
    protected void initView() {
        banner = (Banner) findViewById(R.id.banner);
        introduce = (TextView) findViewById(R.id.introduce);
        shippingMethod = (TextView) findViewById(R.id.shippingMethod);
        priceList = (TextView) findViewById(R.id.priceList);

        banner.setDelayTime(3000);
    }

    @Override
    protected void initData() {
        final int companyId = getIntent().getIntExtra("id", -1);

        api.getLogisticsCompanyDetail(companyId).enqueue(new NetCallBack<LogisticsCompanyDetail>() {
            @Override
            public void onResponse(Call<LogisticsCompanyDetail> call, Response<LogisticsCompanyDetail> response) {
                if (response.body() == null) return;

                final LogisticsCompanyDetail.DataBean data = response.body().getData();
                //TODO 展示物流公司咨询轮播


                //展示公司基础信息
                Objects.requireNonNull(getSupportActionBar()).setTitle(String.valueOf(data.getName()));
                introduce.setText(String.valueOf(data.getIntroduce()));
                shippingMethod.setText(String.valueOf(data.getShippingMethod()));
                //TODO 运费介绍
                priceList.setText(String.valueOf(data.getPriceList()));
            }
        });
    }

    @Override
    protected void initEvent() {
        banner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object o, ImageView imageView) {
                Glide.with(context)
                        .load(Constant.BASE_URL + o)
                        .into(imageView);
            }
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "";
    }
}